/*
	File:	video/Graphics.hpp
	Date:	2013-06-09
	Author:	Asteroth
*/

#ifndef __ZEN_GRAPHICS_HPP__
#define __ZEN_GRAPHICS_HPP__

#include "Material.hpp"
#include "State.hpp"

#define ZEN_SHADER_LOCATION_VERTEX_POSITION     0
#define ZEN_SHADER_LOCATION_VERTEX_TEXCOORD     1
#define ZEN_SHADER_LOCATION_VERTEX_NORMAL       2
#define ZEN_SHADER_LOCATION_VERTEX_COLOR        3

namespace zen {

	namespace video {


		class Graphics {

		private:

			static glm::mat4 modelView;
			static glm::mat4 projection;
			static Material material;
			static int activeTexture;
			static std::map<GLenum, std::string> glErrorStrings;


		public:

			static void clear(bool colorBuffer = true, bool depthBuffer = false);

			static void setModelView(const glm::mat4 &modelView);

			static void setProjection(const glm::mat4 &projection);

			static glm::mat4 getModelView() { return modelView; }
			static glm::mat4 getProjection() { return projection; }
			static Material getMaterial() { return material; }
			static int getActiveTexture() { return activeTexture; }

			static std::string getErrorString();

		};


		inline void Graphics::clear(bool colorBuffer, bool depthBuffer) {
			glClear((colorBuffer ? GL_COLOR_BUFFER_BIT : 0) | (depthBuffer ? GL_DEPTH_BUFFER_BIT : 0));
		}

		inline void Graphics::setModelView(const glm::mat4 &modelView) {
			Graphics::modelView = modelView;
			glMatrixMode(GL_MODELVIEW);
			glLoadMatrixf(glm::value_ptr(Graphics::modelView));
		}

		inline void Graphics::setProjection(const glm::mat4 &projection) {
			Graphics::projection = projection;
			glMatrixMode(GL_PROJECTION);
			glLoadMatrixf(glm::value_ptr(Graphics::projection));
			glMatrixMode(GL_MODELVIEW);
		}

	} // namespace video

} // namespace egl

#endif
